<template>
  <div>
    <div
      class="add"
      @click="userChooseDialogShow1 = true"
    >选择人员</div>
    <eagle-page-list
      ref="eaglePageList"
      @bindData="bindData"
      :queryParams="queryParams"
      placeholder="请输入姓名搜索"
      :controller="controller"
      :conditions="conditions"
      :pageSize="20"
    >

      <div slot="list">
        <eagle-cell
          style="margin-top: 10px"
          class="br-8"
          v-for="(item, index) in list"
          :key="index"
        >
          <div>
            <div>
              <eagle-row gutter="20">
                <eagle-col>
                  <img
                    class="icon"
                    src="@/assets/Images/AppIcon/icon_list_user.png"
                  />姓名：{{ item.UserChnName }}
                </eagle-col>
              </eagle-row>
              <eagle-row gutter="20">
                <eagle-col>
                  <img
                    class="icon"
                    src="@/assets/Images/AppIcon/icon_list_type.png"
                  />部门：{{ item.OrgName  }}
                </eagle-col>
              </eagle-row>
              <eagle-row gutter="20">
                <eagle-col>
                  <img
                    class="icon"
                    src="@/assets/Images/AppIcon/icon_list_type.png"
                  />岗位：{{ item.PostName }}
                </eagle-col>
              </eagle-row>
              <van-divider />
              <div class="op_btn">
                <div
                  class="btn_item"
                  @click="deletePlan1(item)"
                >
                  <img
                    src="@/assets/Images/AppIcon/icon_list_delete.png"
                    alt=""
                  />
                  <div class="mr-10">移除</div>
                </div>
              </div>
            </div>
          </div>
        </eagle-cell>
      </div>
    </eagle-page-list>
    <!-- <user-choose-dialog title="选择协助人员" :show.sync="userChooseDialogShow1" :IsAccounted="true" :isMulti="true" @callback="userChooseCallback1">
        </user-choose-dialog> -->
    <user-choose
      :show.sync="userChooseDialogShow1"
      :tagData="userTagData"
      @callback="userChooseCallback1"
      :isMulti="true"
      ref="userChoose"
    >
    </user-choose>
  </div>

</template>
<script>
import UserChooseDialog from "@/views/components/user/userChooseDialog.vue";
import userChoose from "@/views/components/user/userChooseDialog.vue";
export default {
  components: { userChoose, UserChooseDialog },
  data() {
    return {
      value: "",
      list: [],
      controller: "/WhAccidentInitialReportSend",
      userChooseDialogShow1: false,
      myLoading: false,
      myFinished: false,
      userChooseDialogShow: false,
      deptChooseDialogShow: false,
      searchValue: "",
      userTagData: [],
      conditions: {},
      title: "选择协助人员",
      queryParams: {
        dataType: "Assist",
        AccidentNumber: this.$route.query.AccidentNumber,
      },
    };
  },
  created() {},
  mounted() {
    //this.queryPage();
  },
  methods: {
    deletePlan1(item) {
      //调查报告删除
      const that = this;
      that.$dialog
        .confirm({
          title: "询问",
          message: "您确定要移除该协助人员吗？",
        })
        .then(() => {
          that.$axios
      	  .get("/WhAccidentInitialReportSend/Delete",{params:{ id: item.ID }})
          .then((res) => {
            that.$toast.success("移除成功！");
            setTimeout(() => {
              that.$refs.userChoose.deleteSelect(item.UserName);
              that.$refs.eaglePageList.search({});
            }, 300);
          });
        })
        .catch(() => {
          // on cancel
        });
    },
    userChooseCallback1(data) {
      this.loading = true;
      let _this = this;
      var form1 = {};
      var UserNames = [];
      this.list.forEach((item1) => {
        data = data.filter((item) => item.name != item1.UserChnName);
      });
      data.map((item) => {
        UserNames.push(item.code);
      });
      form1.IsAssist = true;
      form1.UserNames = UserNames;
      form1.AccidentNumber = this.$route.query.AccidentNumber;
      _this.$axios
      .post("/WhAccidentInitialReportSend/Save",form1)
        .then((res) => {
          _this.loading = false;
          _this.userChooseDialogShow1 = false;
          setTimeout(() => {
            _this.$refs.eaglePageList.search({});
          }, 300);
          _this.$toast.success("设置成功");
        })
        .catch((err) => {
          console.log("err", err);
        });
    },

    bindData(data) {
      this.list = [];
      this.userTagData = [];
      if (data) {
        if (data.length > 0) {
          data.forEach((item) => {
            this.userTagData.push({
              code: item.UserName,
              UserName: item.UserChnName,
            });
          });
        }

        this.list = data;
      }
    },
  },
};
</script>
<style lang="less" scoped>
.phone {
  position: relative;
  .code {
    position: absolute;
    right: 20px;
    top: 20px;
    font-size: 12px;
  }
}
.register-info {
  background-color: #e8f1f8;
  padding-bottom: 20px;
}
.img-box {
  height: 50px;
  width: 50px;
  padding: 10px;
  position: absolute;
  left: 50%;
  top: 60px;
  background-color: #fff;
  border-radius: 50%;
  overflow: hidden;
}
.popup-title {
  line-height: 35px;
  padding: 10px;
  font-size: 15px;
  padding-left: 20px;
}

.op_btn {
  display: flex;
  justify-content: flex-end;
  .btn_item {
    display: flex;
    align-items: center;
    img {
      height: 15px;
      width: 15px;
      margin-right: 5px;
    }
  }
}
</style>